<?php

namespace app\ctrl;

use core\lib\Config;
use core\lib\Log;

class IndexCtrl extends \core\Base
{
    public function index()
    {
        /*$this->assign('title', 'hello world');
        $this->assign('name', 'singsong');
        $this->assign('data', [1, 2, 3]);
        $this->display('index.html');*/
    }

    public function upload()
    {
        $this->display('upload.html');
    }

    public function uploader()
    {
        $this->display('uploader.html');
    }

    public function getConf()
    {
        $dbConf = Config::get('default', 'database');
        $dbConf2 = Config::get('db2', 'database');
        p($dbConf, $dbConf2);
    }

    public function db()
    {
        $userBus = new \app\common\business\User();
        $user = $userBus->getUserById(11);
        p($user);

        $userMod = new \app\model\UserModel();
        $data = $userMod->lists();

        $advMod = new \app\model\AdvertModel();
        $data2 = $advMod->lists();
        return format_return(200, $data2);
    }

    public function log() {
        Log::log('test11111111111111');
    }

    public function page0()
    {
        $userBus = new \app\common\business\User();
        $user = $userBus->getUserById(11);
        p($user);

        $userMod = new \app\model\UserModel();
        $data = $userMod->lists();

        $advMod = new \app\model\AdvertModel();
        $data2 = $advMod->lists();
        return format_return(200, $data2);
    }

    public function page() {
        $page = isset($_GET['page']) ? $_GET['page'] : 1;
        $page_size = 2;
        //$start = ($page - 1) * $page_size;

        /*****数据库*****/
        $userBus = new \app\common\business\User();
        $select_count = $userBus->getUserCount();
        //p($select_count);
        /*****数据库*****/

        $p = new \app\common\lib\Page($select_count['count'], 5, $page, $page_size);

        $page_str = $p->showPages(1);
        var_dump($page_str);
        //p($_GET);
    }

    public function page2() {
        $p2 = new \app\common\lib\Page2(23, 5);
        $page_str = $p2->showPages();
        p($page_str);
    }
}